<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *客户列表
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$tabs=array(
	array('op'=>'list','title'=>'网络渠道数据'),
);
if($_SESSION['juese_id']>6 && $_SESSION['juese_id']<15){
	exi('您无权访问！','error');
}
//客户列表
if($_RQ['op']=='list'){
	$params=array('from_type'=>2,'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']);
	if($_RQ['from2_type']){
		$types=array($_RQ['from2_type']=>$this->member_from2_type[$_RQ['from2_type']]);
	}else{
		$types=$this->member_from2_type;
	}
	if($types){
		$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
		$starttime = mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y'));
		$weektime = $starttime+7*24*3600;
		$monthtime=strtotime(date('Ym').'01');
		$status4=array(4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,32,33,34,35,36,37,38,39,40,41,42,100);
		$list=array();
		foreach($types as $k=>$v){
			$item=array();
			$item['title']=$v;
			$item['allnum']=pdo_count('jy_yxw_member',array('from_type'=>2,'from2_type'=>$k,'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']));
			$item['daynum']=pdo_count('jy_yxw_member',array('createtime >'=>$daytime,'from_type'=>2,'from2_type'=>$k,'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']));
			$item['weeknum']=pdo_count('jy_yxw_member',array('createtime >'=>$weektime,'from_type'=>2,'from2_type'=>$k,'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']));
			$item['monthnum']=pdo_count('jy_yxw_member',array('createtime >'=>$monthtime,'from_type'=>2,'from2_type'=>$k,'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']));
			$item['allnum2']=pdo_count('jy_yxw_member',array('status'=>$status4,'from_type'=>2,'from2_type'=>$k,'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']));
			$item['daynum2']=pdo_count('jy_yxw_member',array('status'=>$status4,'zhun_time >'=>$daytime,'from_type'=>2,'from2_type'=>$k,'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']));
			$item['weeknum2']=pdo_count('jy_yxw_member',array('status'=>$status4,'zhun_time >'=>$weektime,'from_type'=>2,'from2_type'=>$k,'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']));
			$item['monthnum2']=pdo_count('jy_yxw_member',array('status'=>$status4,'zhun_time >'=>$monthtime,'from_type'=>2,'from2_type'=>$k,'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']));
			$item['rate']=0;
			if($item['allnum']>0){
				$item['rate']=$item['allnum2']*100/$item['allnum'];
				$item['rate']=price($item['rate']);
			}
			$list[]=$item;
		}
	}
	$return['list']=$list;
	//页面显示设置
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'export'=>'export',
		'list'=>array('data'=>'list','del_one'=>false,'delall'=>false,'edit'=>false,'list'=>array(
			array('name'=>'title','title'=>'类型','type'=>'string'),
			array('name'=>'allnum','title'=>'总量','type'=>'string'),
			array('name'=>'daynum','title'=>'当天量','type'=>'string'),
			array('name'=>'weeknum','title'=>'当周量','type'=>'string'),
			array('name'=>'monthnum','title'=>'当月量','type'=>'string'),
			array('name'=>'allnum2','title'=>'总意向','type'=>'string'),
			array('name'=>'daynum2','title'=>'当天意向','type'=>'string'),
			array('name'=>'weeknum2','title'=>'当周意向','type'=>'string'),
			array('name'=>'monthnum2','title'=>'当月意向','type'=>'string'),
			array('name'=>'rate','title'=>'意向转化率','type'=>'unitstring','unit'=>'%'),
		)),
		'search'=>array(
			array('name'=>'from2_type','width'=>15,'title'=>'网络来源','type'=>'radio','options'=>'from2_type'),
		),
	);
	$return['from2_type']=$this->member_from2_type;
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='export'){
	//客户列表
	$return['params']=array();
	$params=array('juese'=>5,'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']);
	$types=$this->member_from2_type;
	if($types){
		$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
		$starttime = mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y'));
		$weektime = $starttime+7*24*3600;
		$monthtime=strtotime(date('Ym').'01');
		$status4=array(4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,32,33,34,35,36,37,38,39,40,41,42,100);
		$list=array();
		foreach($types as $k=>$v){
			$item=array();
			$item['title']=$v;
			$item['allnum']=pdo_count('jy_yxw_member',array('from_type'=>2,'from2_type'=>$k,'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']));
			$item['daynum']=pdo_count('jy_yxw_member',array('createtime >'=>$daytime,'from_type'=>2,'from2_type'=>$k,'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']));
			$item['weeknum']=pdo_count('jy_yxw_member',array('createtime >'=>$weektime,'from_type'=>2,'from2_type'=>$k,'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']));
			$item['monthnum']=pdo_count('jy_yxw_member',array('createtime >'=>$monthtime,'from_type'=>2,'from2_type'=>$k,'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']));
			$item['allnum2']=pdo_count('jy_yxw_member',array('status'=>$status4,'from_type'=>2,'from2_type'=>$k,'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']));
			$item['daynum2']=pdo_count('jy_yxw_member',array('status'=>$status4,'zhun_time >'=>$daytime,'from_type'=>2,'from2_type'=>$k,'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']));
			$item['weeknum2']=pdo_count('jy_yxw_member',array('status'=>$status4,'zhun_time >'=>$weektime,'from_type'=>2,'from2_type'=>$k,'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']));
			$item['monthnum2']=pdo_count('jy_yxw_member',array('status'=>$status4,'zhun_time >'=>$monthtime,'from_type'=>2,'from2_type'=>$k,'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']));
			$item['rate']=0;
			if($item['allnum']>0){
				$item['rate']=$item['allnum2']*100/$item['allnum'];
				$item['rate']=price($item['rate']);
			}
			$list[]=$item;
		}
	}
	$header=array(
		'title'=>'类型',
		'allnum'=>'总量',
		'daynum'=>'当天量',
		'weeknum'=>'当周量',
		'monthnum'=>'当月量',
		'allnum2'=>'总意向',
		'daynum2'=>'当天意向',
		'weeknum2'=>'当周意向',
		'monthnum2'=>'当月意向',
		'rate'=>'意向转化率',
	);
	model('core/tools')->export2excel($header,$list,'网络渠道数据');
}